﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CarInfor.DAL;


namespace CarInfor.UI
{
    public partial class frmLogin : Form
    {

        public frmLogin()
        {
            InitializeComponent();
            MyGlobal.curUser = new UserInfor();
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            if (!CheckInput())
            {
                return;
            }
            string sql = " [UserName]='" + this.txtUserName.Text.Trim().Replace("'", "''") + "' and [Password]='" + this.txtPassword.Text.Trim().Replace("'", "''") + "'";
            DataTable dt = MyGlobal.curUser.Query(sql);
            if (dt.Rows.Count > 0)
            {
                MyGlobal.curUser.ID = dt.Rows[0]["编号"].ToString();
                MyGlobal.curUser.UserName = dt.Rows[0]["用户名"].ToString();
                MyGlobal.curUser.Password = dt.Rows[0]["密码"].ToString();
                this.DialogResult = DialogResult.OK;
            }
            else
            {
                MessageHelper.ShowInfo("用户名或密码错误！");
            }
        }

        bool CheckInput()
        {
            if (this.txtUserName.Text.Trim() == "")
            {
                MessageHelper.ShowInfo("请输入用户名！");
                return false;
            }
            if (this.txtPassword.Text.Trim() == "")
            {
                MessageHelper.ShowInfo("请输入密码！");
                return false;
            }
            return true;
        }

        private void btnCancle_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void frmLogin_Load(object sender, EventArgs e)
        {

        }
    }
}
